import { ElMessage } from "element-plus";
import router from "@/router";
import { useUserStore } from "@/stores/user";

//路由白名单
const WHITE_LIST = ["/login", "/404"];

//路由导航守卫
router.beforeEach((to, from, next) => {
    const store = useUserStore()
    //判断是否为token
    if (store.token) {
        //有token 放行
        next()
    } else {
        if (WHITE_LIST.includes(to.path)) {
            //白名单 放行
            next()
        } else {
            //没有token 跳转到登录页
            ElMessage.error("请先登录")
            next("/login")
        }
    }
})